<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="p" %>
<s:include value="/js/validators/user.jsp"></s:include>
  <div class="f_l margin1" style="width:100%">
    <div style="height:24px;color:red" align="center" id="errorInfo">${failInfo }</div>
    <div style="height:24px;color:red;font-weight:bold" align="left">修改用户</div>
    <s:form id="submitForm" action="user!update" method="post" theme="simple">
    <input type="hidden" id="user.id" name="user.id" value="${user.id}">
    <table>
    	<tbody>
    		<tr>
    			<td><s:text name="用户名"/>：</td>
    			<td><input maxlength="25" type="text" name="user.userName" value="${user.userName}" /></td>
    			<td><s:text name="电子邮件"/>：</td>
    			<td><input maxlength="25" type="text" name="user.email"  value="${user.email}"></td>
    		</tr>
    		<tr>
    			<td><s:text name="设置密码"/>：</td>
    			<td><input maxlength="14" type="password" name="user.password" value="${user.password}"></td>
    			<td><s:text name="确认密码"/>：</td>
    			<td><input maxlength="14" type="password" name="user.repassword"  value="${user.password}"></td>
    		</tr>
    		<tr>
    			<td><s:text name="手机"/>：</td>
    			<td><input maxlength="13" type="text" name="user.mobile"  value="${user.mobile}"></td>
    			<td><s:text name="传真"/>：</td>
    			<td><input maxlength="25" type="text" name="user.fax"  value="${user.fax}"></td>
    		</tr>
    		<tr>
    			<td><s:text name="公司"/>：</td>
    			<td> 
	    			${user.companyName}
	           	</td>
    			<td><s:text name="职位"/>：</td>
    			<td> 
	    			<select onchange="javascript:commonSelect(this,'user.positionName');" name="user.positionId" id="positions">
		                <s:iterator value="allPositions" status="status">
		                    <option value="${id}" <s:if test="%{user.positionId == id}">selected="selected"</s:if>>${name}</option>
		                </s:iterator>
	           		</select>
           		</td>
    		</tr>
    		<tr>
    			<td><s:text name="类型"/>：</td>
    			<td> 
	    			<select onchange="javascript:commonSelect(this,'user.userTypeName');" name="user.userTypeId" >
		                <option value="">-- 请选择 --</option>
			            <s:iterator value="allUsertypes" status="status">
			                <option value="${id}" <s:if test="%{user.userTypeId == id}">selected="selected"</s:if>>${name}</option>
			            </s:iterator>
		            </select>
                </td>
    		</tr>
    		<tr>
    			<td colspan="4">
    			   <s:text name="国家"/>：<input maxlength="25" type="text" name="user.country"  value="${user.country}">
		           <s:text name="省"/>：<input maxlength="25" type="text" name="user.province"  value="${user.province}">
		           <s:text name="市"/>：<input maxlength="25" type="text" name="user.city"  value="${user.city}">
    			</td>
    		</tr>
    		<tr>
    			<td colspan="4">
    				<s:text name="地址"/>：<input maxlength="50" type="text" name="user.address" style="width: 450px;" value="${user.address}">
    			</td>
    		</tr>
    		<tr>
    			<td colspan="4" align="center">
    				<input type="submit" value="确认" onclick="return doValidate(event);"/>
		            &nbsp;&nbsp;
		            <input type="button" value="取消" onclick="window.location.href='user!list'"/>
    			</td>
    		</tr>
    	</tbody>
    </table>
    <input type="hidden" id="user.userTypeName" name="user.userTypeName" />
    <input type="hidden" id="user.companyName" name="user.companyName" value="${user.companyName}">
    <input type="hidden" id="user.companyId" name="user.companyId" value="${user.companyId}">
    <input type="hidden" id="user.positionName" name="user.positionName" />
    </s:form>
  </div>
  <script type="text/javascript">
	  function getPositions(){
	      var companyId = document.getElementById("user.companyId").value;
	
	      $.ajax({
	    	  type: "POST",
	    	  url: "<s:url action='position!getPositionsByCompanyId' namespace='/position' />",
	    	  data: "companyId=" + companyId,
	    	  complete:function(response){
	          var data = response.responseText;
	    	  if(null != data && "" != data){
			       var positions = data.split(";");
			       var html = "";
			       for(var i = 0; i < positions.length; i++){
			           var p = positions[i].split(",");
			           html += "<option value='" + p[0]+ "'>" + p[1] + "</option>";
			       }
			       $("#positions").html(html);
		        }else{
		           $("#positions").html("<option value=''>无</option>");
		        }
	          }
	      }); 
	  }
  </script>
